package fashionshop.bll;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import database.MySQLConnect;

/**
 *
 * @author Cafeitvn.com
 */
public class ReportBLL {

    /**
     * @param args the command line arguments
     * @throws JRException 
     */
	
	private Connection connect = null; // database connection
	private String url = "jdbc:mysql://localhost:3306/fashion_shop";
	private String filepath = "d:\\reports\\Simple_Blue.jrxml";
    
    public static void showReport() throws JRException{
    	
//    	String jrxmlFileName = "d:\\reports\\report1.jrxml";
    	String jasperFileName = "reports/report1.jasper";
    	String pdfFileName = "reports/test_jasper.pdf";
    	
    	MySQLConnect connect = new MySQLConnect(); 

    	Map parameters = new HashMap();
    	
//    	JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFileName);
//    	JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    	JasperPrint jasperPrint = null;
		try {
			jasperPrint = JasperFillManager.fillReport(jasperFileName, parameters, connect.getConnect());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	JasperExportManager.exportReportToPdfFile(jasperPrint, pdfFileName); 
    	try {
			Desktop.getDesktop().open(new File(pdfFileName));
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}     
    }

    public static void main(String[] args) throws JRException, ClassNotFoundException {

    	ReportBLL.showReport();
    }
}